﻿Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data
Imports System.Collections.Generic

Namespace Pic
    Public Class Follow
        Inherits clsBase
#Region "Private Variables"
        Private _FerEmail As String
        Private _FedEmail As String
        Private _Created As DateTime
#End Region
#Region "Properties"
        Public Property FerEmail() As String
            Get
                Return _FerEmail
            End Get
            Set(ByVal value As String)
                _FerEmail = value
            End Set
        End Property
        Public Property FedEmail() As String
            Get
                Return _FedEmail
            End Get
            Set(ByVal value As String)
                _FedEmail = value
            End Set
        End Property
        Public Property Created() As DateTime
            Get
                Return _Created
            End Get
            Set(ByVal value As DateTime)
                _Created = value
            End Set
        End Property

#End Region
#Region "Constructors"
        Public Sub New(ByVal FerEmail_ As String, ByVal FedEmail_ As String, ByVal Created_ As DateTime)
            Me.FerEmail = FerEmail_
            Me.FedEmail = FedEmail_
            Me.Created = Created_
        End Sub
#End Region
#Region "Methods"
        Private Shared Function GetFollowFromReader(ByVal reader_ As IDataReader) As Follow
            Dim rtrn As Follow = New Follow(reader_("Fer_Email"), reader_("Fed_Email"), reader_("Created"))
            Return rtrn
        End Function

        Public Shared Function GetFollowByEmail(ByVal FerEmail_ As String, ByVal FedEmail_ As String) As Follow
            Dim conn As New SqlConnection(ConnectionString)
            Dim veriString As String = "Select * from tbl_Follow where Fer_Email=@Fer_Email AND Fed_Email=@Fed_Email"
            Dim reader As IDataReader
            Try
                conn.Open()
                Dim cmd As New SqlCommand(veriString, conn)
                cmd.CommandType = CommandType.Text
                cmd.Parameters.Add("@Fer_Email", SqlDbType.VarChar).Value = FerEmail_
                cmd.Parameters.Add("@Fed_Email", SqlDbType.VarChar).Value = FedEmail_
                reader = ExecuteReader(cmd, CommandBehavior.SingleRow)
                If reader.Read Then
                    Return GetFollowFromReader(reader)
                Else
                    Return Nothing
                End If
            Catch ex As Exception
                Throw ex
            Finally
                conn.Close()
            End Try
        End Function

        Private Shared Function GetFollowListFromReader(ByVal reader As IDataReader) As List(Of Follow)
            Dim rtrnList As New List(Of Follow)
            Do While reader.Read
                rtrnList.Add(GetFollowFromReader(reader))
            Loop
            Return rtrnList
        End Function
        Public Shared Function GetFollowListByFilter(ByVal Filtre_ As String, ByVal FiltreOrder_ As String) As List(Of Follow)
            Dim conn As New SqlConnection(ConnectionString)
            Dim veriString As String = "select * from website1.dbo.tbl_Follow where " & Filtre_ & "' order by " & FiltreOrder_ & " asc"
            Try
                conn.Open()
                Dim cmd As New SqlCommand(veriString, conn)
                cmd.CommandType = CommandType.Text
                Return GetFollowListFromReader(ExecuteReader(cmd, CommandBehavior.Default))
            Catch ex As Exception
                Throw ex
            Finally
                conn.Close()
            End Try
        End Function


        Public Shared Function InsertFollow(ByVal FerEmail_ As String, ByVal FedEmail_ As String) As Integer
            Dim conn As New SqlConnection(ConnectionString)
            Dim veriString As String = "insert into tbl_Follow(Fer_Email,Fed_Email,created) values(@Fer_Email,@Fed_Email,@created)"
            Try
                conn.Open()
                Dim cmd As New SqlCommand(veriString, conn)
                cmd.CommandType = CommandType.Text
                cmd.Parameters.Add("@Fer_Email", SqlDbType.VarChar).Value = FerEmail_
                cmd.Parameters.Add("@Fed_Email", SqlDbType.VarChar).Value = FedEmail_
                cmd.Parameters.Add("@created", SqlDbType.DateTime).Value = Now.Date
                Return ExecuteNonQuery(cmd)
            Catch ex As Exception
                Throw ex
            Finally
                conn.Close()
            End Try
        End Function

        'Public Shared Function UpdateFollow(ByVal FerEmail_ As Integer, ByVal FedEmail_ As Boolean) As Integer
        '    Dim conn As New SqlConnection(ConnectionString)
        '    Dim veriString As String = "update tbl_Follow set Modified=@Modified where Board_ID = @Board_ID AND Object_ID=@Object_ID"
        '    Try
        '        conn.Open()
        '        Dim cmd As New SqlCommand(veriString, conn)
        '        cmd.CommandType = CommandType.Text
        '        cmd.Parameters.Add("@Board_ID", SqlDbType.Int).Value = BoardID_
        '        cmd.Parameters.Add("@Object_ID", SqlDbType.Int).Value = ObjectID_
        '        cmd.Parameters.Add("@modified", SqlDbType.DateTime).Value = Now.Date
        '        Return ExecuteNonQuery(cmd)
        '    Catch ex As Exception
        '        Throw ex
        '    Finally
        '        conn.Close()
        '    End Try
        'End Function
        Public Shared Function DeleteFollow(ByVal FerEmail_ As String, ByVal FedEmail_ As String) As Boolean
            Dim conn As New SqlConnection(ConnectionString)
            Dim veriString As String = "Select count(1) from tbl_Follow Where Fer_Email=@Fer_Email AND Fed_Email=@Fed_Email"
            Dim count As Integer
            Try
                conn.Open()
                Dim cmd As New SqlCommand(veriString, conn)
                cmd.Parameters.Add("@Fer_Email", SqlDbType.VarChar).Value = FerEmail_
                cmd.Parameters.Add("@Fed_Email", SqlDbType.VarChar).Value = FedEmail_
                count = ExecuteScalar(cmd)
                If count = 0 Then
                    Return False
                Else
                    cmd.CommandText = "Delete from tbl_Follow Where Fer_Email=@Fer_Email AND Fed_Email=@Fed_Email"
                    cmd.CommandType = CommandType.Text
                    cmd.Parameters.Add("@Fer_Email", SqlDbType.VarChar).Value = FerEmail_
                    cmd.Parameters.Add("@Fed_Email", SqlDbType.VarChar).Value = FedEmail_
                    Return ExecuteNonQuery(cmd)
                End If
            Catch ex As Exception
                Throw ex
            Finally
                conn.Close()
            End Try
        End Function

        'Public Shared Function SilinebilirMi(ByVal ProjeID_ As Integer) As Boolean
        '    Dim conn As New SqlConnection(ConnectionString)
        '    Dim veriString As String = "Select count(1) from tblSondajlar where ProjeID=" & ProjeID_
        '    Dim count As Integer
        '    Try
        '        conn.Open()
        '        Dim cmd As New SqlCommand(veriString, conn)
        '        count = ExecuteScalar(cmd)
        '        If count = 0 Then
        '            Return True
        '        Else
        '            Return False
        '        End If
        '    Catch ex As Exception
        '        Throw ex
        '    Finally
        '        conn.Close()
        '    End Try
        'End Function
#End Region
    End Class
End Namespace

